options ls = 100 ps = 80 probsig = 2;

data fuzzy1;
   informat code $20.;informat bcode $20.;
   infile 'c:/My Documents/data/AAT.1/SDoneIATA.dat' delimiter='09'x;
   input date time $ build sub code $ block trial lat resp $ corr trialitm bcode $;
data fuzzy2;
   informat code $20.;informat bcode $20.;
   infile 'c:/My Documents/data/AAT.1/SDoneIATB.dat' delimiter='09'x;
   input date time $ build sub code $ block trial lat resp $ corr trialitm bcode $;
data fuzzy3;
   informat code $20.;informat bcode $20.;
   infile 'c:/My Documents/data/AAT.1/SDoneIATB2.dat' delimiter='09'x;
   input date time $ build sub code $ block trial lat resp $ corr trialitm bcode $;
data fuzzy5;
   informat code $20.;informat bcode $20.;
   infile 'c:/My Documents/data/AAT.1/SDoneIATF.dat' delimiter='09'x;
   input date time $ build sub code $ block trial lat resp $ corr trialitm bcode $;
data fuzzy6;
   informat code $20.;informat bcode $20.;
   infile 'c:/My Documents/data/AAT.1/SDoneIATA2.dat' delimiter='09'x;
   input date time $ build sub code $ block trial lat resp $ corr trialitm bcode $;
data temp;
  set fuzzy1 fuzzy2 fuzzy3 fuzzy5 fuzzy6;

if sub in (3) then delete; /*bad subject*/
if block in (1,2) then delete;if trial < 19 then delete;if bcode = 'bcode' then delete;

if code in ('bugs_false1000', 'fruit_false1000', 'good_false1000', 'bad_false1000',
             'bugs_false833', 'fruit_false833', 'good_false833', 'bad_false833',
             'bugs_false666', 'fruit_false666', 'good_false666', 'bad_false666',
             'bugs_false500', 'fruit_false500', 'good_false500', 'bad_false500')
then item = 0;else item = 1;

if corr = 0 and item = 0 then response = 'corrrej';
if corr = 0 and item = 1 then response = 'miss';
if corr = 1 and item = 0 then response = 'falsalr';
if corr = 1 and item = 1 then response = 'hit';

/*proc freq;tables bcode*response;run;*/
proc means n mean std; class code response; var lat; run;

proc sort;  by sub bcode response; run;
proc means noprint data=temp n;
  by sub bcode response;  var lat; output out=means  mean=speed; run;
proc transpose data=means prefix=speed name=name out=spdmeans;
  by sub bcode response;run;
proc sort; by name; run;
data prac;  set spdmeans; if name ^= '_FREQ_' then delete;
   /*if speed1 < 0 then speed1 = 0;*/
   if response = 'corrrej' then do;
      if speed1 = 20 then do; response = 'falsalr'; speed1 = 0.35; end;
      else delete; end;
   if response = 'miss' then do;
      if speed1 = 20 then do; response = 'hit'; speed1 = 0.35; end;
      else delete; end;
   if response = 'hit' and speed1 = 20 then speed1 = 19.65;
   if response = 'falsalr' and speed1 = 20 then speed1 = 19.65;
proc sort; by sub;
proc transpose data=prac prefix=freq name=name out=freq;
  by sub; run;
proc sort; by name; run;
data prac; set freq;
   pbgbd999 = freq1/20; pHbgbd99 = freq2/20;
   pbgbd500 = freq3/20; pHbgbd50 = freq4/20;
   pbgbd666 = freq5/20; pHbgbd66 = freq6/20;
   pbgbd833 = freq7/20; pHbgbd83 = freq8/20;
   pbggd999 = freq9/20; pHbggd99 = freq10/20;
   pbggd500 = freq11/20; pHbggd50 = freq12/20;
   pbggd666 = freq13/20; pHbggd66 = freq14/20;
   pbggd833 = freq15/20; pHbggd83 = freq16/20;
   pftbd999 = freq17/20; pHftbd99 = freq18/20;
   pftbd500 = freq19/20; pHftbd50 = freq20/20;
   pftbd666 = freq21/20; pHftbd66 = freq22/20;
   pftbd833 = freq23/20; pHftbd83 = freq24/20;
   pftgd999 = freq25/20; pHftgd99 = freq26/20;
   pftgd500 = freq27/20; pHftgd50 = freq28/20;
   pftgd666 = freq29/20; pHftgd66 = freq30/20;
   pftgd833 = freq31/20; pHftgd83 = freq32/20;

   Fbgbd999 = probit(freq1/20); Hbgbd999 = probit(freq2/20);
   Fbgbd500 = probit(freq3/20); Hbgbd500 = probit(freq4/20);
   Fbgbd666 = probit(freq5/20); Hbgbd666 = probit(freq6/20);
   Fbgbd833 = probit(freq7/20); Hbgbd833 = probit(freq8/20);
   Fbggd999 = probit(freq9/20); Hbggd999 = probit(freq10/20);
   Fbggd500 = probit(freq11/20); Hbggd500 = probit(freq12/20);
   Fbggd666 = probit(freq13/20); Hbggd666 = probit(freq14/20);
   Fbggd833 = probit(freq15/20); Hbggd833 = probit(freq16/20);
   Fftbd999 = probit(freq17/20); Hftbd999 = probit(freq18/20);
   Fftbd500 = probit(freq19/20); Hftbd500 = probit(freq20/20);
   Fftbd666 = probit(freq21/20); Hftbd666 = probit(freq22/20);
   Fftbd833 = probit(freq23/20); Hftbd833 = probit(freq24/20);
   Fftgd999 = probit(freq25/20); Hftgd999 = probit(freq26/20);
   Fftgd500 = probit(freq27/20); Hftgd500 = probit(freq28/20);
   Fftgd666 = probit(freq29/20); Hftgd666 = probit(freq30/20);
   Fftgd833 = probit(freq31/20); Hftgd833 = probit(freq32/20);
   Dbgbd999 = Hbgbd999 - Fbgbd999; Dbggd999 = Hbggd999 - Fbggd999;
   Dftbd999 = Hftbd999 - Fftbd999; Dftgd999 = Hftgd999 - Fftgd999;
   Dbgbd833 = Hbgbd833 - Fbgbd833; Dbggd833 = Hbggd833 - Fbggd833;
   Dftbd833 = Hftbd833 - Fftbd833; Dftgd833 = Hftgd833 - Fftgd833;
   Dbgbd666 = Hbgbd666 - Fbgbd666; Dbggd666 = Hbggd666 - Fbggd666;
   Dftbd666 = Hftbd666 - Fftbd666; Dftgd666 = Hftgd666 - Fftgd666;
   Dbgbd500 = Hbgbd500 - Fbgbd500; Dbggd500 = Hbggd500 - Fbggd500;
   Dftbd500 = Hftbd500 - Fftbd500; Dftgd500 = Hftgd500 - Fftgd500;
   Fruit999 = Dftgd999 - Dftbd999; Bugs999 = Dbggd999 - Dbgbd999;
   Fruit833 = Dftgd833 - Dftbd833; Bugs833 = Dbggd833 - Dbgbd833;
   Fruit666 = Dftgd666 - Dftbd666; Bugs666 = Dbggd666 - Dbgbd666;
   Fruit500 = Dftgd500 - Dftbd500; Bugs500 = Dbggd500 - Dbgbd500;
   Fruit = mean(Fruit999,Fruit833,Fruit666,Fruit500);
   Bugs = mean(Bugs999,Bugs833,Bugs666,Bugs500);
   FrtBg999 = Fruit999 - Bugs999;FrtBg833 = Fruit833 - Bugs833;
   FrtBg666 = Fruit666 - Bugs666;FrtBg500 = Fruit500 - Bugs500;
   FrtBug = Fruit - Bugs;

   Fbgbdall = probit((freq1+freq3+freq5+freq7)/80);     Hbgbdall = probit((freq2+freq4+freq6+freq8)/80);
   Fbggdall = probit((freq11+freq13+freq15+freq9)/80);  Hbggdall = probit((freq12+freq14+freq16+freq10)/80);
   Fftbdall = probit((freq21+freq23+freq19+freq17)/80); Hftbdall = probit((freq22+freq24+freq20+freq18)/80);
   Fftgdall = probit((freq31+freq29+freq25+freq27)/80); Hftgdall = probit((freq32+freq30+freq26+freq28)/80);
   Dbgbdall = Hbgbdall - Fbgbdall;   Dbggdall = Hbggdall - Fbggdall;
   Dftbdall = Hftbdall - Fftbdall;   Dftgdall = Hftgdall - Fftgdall;
   FruitAll = Dftgdall - Dftbdall;   BugsAll = Dbggdall - Dbgbdall;

   Zbgbd999 = probit(1 - freq1/20); Zbgbd500 = probit(1 - freq3/20);
   Zbgbd666 = probit(1 - freq5/20); Zbgbd833 = probit(1 - freq7/20);
   Zbggd999 = probit(1 - freq9/20); Zbggd500 = probit(1 - freq11/20);
   Zbggd666 = probit(1 - freq13/20); Zbggd833 = probit(1 - freq15/20);
   Zftbd999 = probit(1 - freq17/20); Zftbd500 = probit(1 - freq19/20);
   Zftbd666 = probit(1 - freq21/20); Zftbd833 = probit(1 - freq23/20);
   Zftgd999 = probit(1 - freq25/20); Zftgd500 = probit(1 - freq27/20);
   Zftgd666 = probit(1 - freq29/20); Zftgd833 = probit(1 - freq31/20);

   ZbgbdAll = probit(1 - ((freq1+freq3+freq5+freq7)/80));
   Zbggdall = probit(1 - ((freq11+freq13+freq15+freq9)/80));
   Zftbdall = probit(1 - ((freq21+freq23+freq19+freq17)/80));
   Zftgdall = probit(1 - ((freq31+freq29+freq25+freq27)/80));

   Bbgbd999 = probnorm(Zbgbd999 - Dbgbd999)/probnorm(Zbgbd999);
   Bbgbd833 = probnorm(Zbgbd833 - Dbgbd833)/probnorm(Zbgbd833);
   Bbgbd666 = probnorm(Zbgbd666 - Dbgbd666)/probnorm(Zbgbd666);
   Bbgbd500 = probnorm(Zbgbd500 - Dbgbd500)/probnorm(Zbgbd500);
   Bbggd999 = probnorm(Zbggd999 - Dbggd999)/probnorm(Zbggd999);
   Bbggd833 = probnorm(Zbggd833 - Dbggd833)/probnorm(Zbggd833);
   Bbggd666 = probnorm(Zbggd666 - Dbggd666)/probnorm(Zbggd666);
   Bbggd500 = probnorm(Zbggd500 - Dbggd500)/probnorm(Zbggd500);
   Bftbd999 = probnorm(Zftbd999 - Dftbd999)/probnorm(Zftbd999);
   Bftbd833 = probnorm(Zftbd833 - Dftbd833)/probnorm(Zftbd833);
   Bftbd666 = probnorm(Zftbd666 - Dftbd666)/probnorm(Zftbd666);
   Bftbd500 = probnorm(Zftbd500 - Dftbd500)/probnorm(Zftbd500);
   Bftgd999 = probnorm(Zftgd999 - Dftgd999)/probnorm(Zftgd999);
   Bftgd833 = probnorm(Zftgd833 - Dftgd833)/probnorm(Zftgd833);
   Bftgd666 = probnorm(Zftgd666 - Dftgd666)/probnorm(Zftgd666);
   Bftgd500 = probnorm(Zftgd500 - Dftgd500)/probnorm(Zftgd500);

   Bbgbdall = probnorm(Zbgbdall - Dbgbdall)/probnorm(Zbgbdall);
   Bbggdall = probnorm(Zbggdall - Dbggdall)/probnorm(Zbggdall);
   Bftbdall = probnorm(Zftbdall - Dftbdall)/probnorm(Zftbdall);
   Bftgdall = probnorm(Zftgdall - Dftgdall)/probnorm(Zftgdall);

data explicit;
  informat major $25.;informat Afavrte $15.;informat ethnicit $15.;
  infile 'c:/My Documents/data/AAT.1/AAT.explicit.1.dat.txt' delimiter='09'x;
  input #1 sub Afruit Abugs Amath Apsych Aengr Aarts Abiology Areading Ascience Aenglish
            Aphysics Aphil AR1 $ AR2 $ AR3 $ AR4 $ AR5 $ AR6 $ AR7 $ AR8 $ AR9 $ AR10 $
            Afavrte $ BSRI1 BSRI2 BSRI3 BSRI4 BSRI5 BSRI6 BSRI7 BSRI8 BSRI9 BSRI10
            BSRI11 BSRI12 BSRI13 BSRI14 BSRI15 BSRI16 BSRI17 BSRI18 BSRI19 BSRI20
            BSRI21 BSRI22 BSRI23 BSRI24 BSRI25 BSRI26 BSRI27 BSRI28 BSRI29 BSRI30
            BSRI31 BSRI32 BSRI33 BSRI34
        #2  BSRI35 BSRI36 BSRI37 BSRI38 BSRI39 BSRI40
            BSRI41 BSRI42 BSRI43 BSRI44 BSRI45 BSRI46 BSRI47 BSRI48 BSRI49 BSRI50
            BSRI51 BSRI52 BSRI53 BSRI54 BSRI55 BSRI56 BSRI57 BSRI58 BSRI59 BSRI60
            GID1 GID2 GID3 GID3 GID5 GID6 GID7 GID8 GID9 GID10 GID11 GID12 GID13 GID14
            year major $ age sex $ ethnicit $ bornUS UShwlng Engfirst Enghwlng
            glasses handed $ sleep alert computer hrsoncmp comfort Dgender Dage Drace Dses;
data IAT;
  infile 'c:/My Documents/data/AAT.1/IATdata.txt' delimiter='09'x;
  input sub fruitgd fruitbd fruitbug mathgd mathbd mathread;

proc sort data=explicit; by sub;run;
data comb;merge prac (in=frog) explicit;by sub;if frog;run;proc sort; by sub;
data comb;merge comb (in=frog) IAT; by sub;if frog; run;proc sort; by sex sub;run;

data comb;set comb;
  masculin = mean (of BSRI1 BSRI4 BSRI7 BSRI10
            BSRI13 BSRI16 BSRI19 BSRI22 BSRI25 BSRI28 BSRI31 BSRI34 BSRI37 BSRI40
            BSRI43 BSRI46 BSRI49 BSRI52 BSRI55 BSRI58);
  feminine = mean (of BSRI2 BSRI5 BSRI8 BSRI11 BSRI14 BSRI17 BSRI20
            BSRI23 BSRI26 BSRI29 BSRI32 BSRI35 BSRI38 BSRI41 BSRI44 BSRI47 BSRI50
            BSRI53 BSRI56 BSRI59);
  neutral  = mean (of BSRI3 BSRI6 BSRI9 BSRI12 BSRI15 BSRI18 BSRI21 BSRI24 BSRI27 BSRI30
            BSRI33 BSRI36 BSRI39 BSRI42 BSRI45 BSRI48 BSRI51 BSRI54 BSRI57 BSRI60);
  GID2 = -GID2; GID4 = -GID4; GID5 = -GID5; GID7 = -GID7; GID9 = -GID9;
  GID11 = -GID11; GID13 = -GID13;
  EgenID = mean(GID1 - GID14); Afrtbug = Afruit - Abugs;

/*overall measure*/
proc means; var Dbgbdall Dbggdall Dftbdall Dftgdall; run;
proc glm;  model Dbgbdall Dbggdall Dftbdall Dftgdall = /nouni;repeated bugfruit 2, badgood 2;run;

proc glm; model Dbgbdall Dbggdall = /nouni;repeated badgood 2;title 'bugs only';run;
proc glm; model Dftbdall Dftgdall = /nouni;repeated badgood 2;title 'fruit only';run;

proc glm; model  Dbgbd999 Dbggd999 Dftbd999 Dftgd999
                 Dbgbd833 Dbggd833 Dftbd833 Dftgd833
                 Dbgbd666 Dbggd666 Dftbd666 Dftgd666
      Dbgbd500 Dbggd500 Dftbd500 Dftgd500 = /nouni;repeated window 4, bugfruit 2, badgood 2;run;

/* sensitivity*/
proc means;
  var Dbgbd999 Dbggd999 Dftbd999 Dftgd999 Dbgbd833 Dbggd833 Dftbd833 Dftgd833
      Dbgbd666 Dbggd666 Dftbd666 Dftgd666 Dbgbd500 Dbggd500 Dftbd500 Dftgd500;run;
proc glm;
  model Dbgbd999 Dbggd999 Dftbd999 Dftgd999 = /nouni;repeated bugfruit 2, badgood 2;run;
proc glm;
  model Dbgbd833 Dbggd833 Dftbd833 Dftgd833 = /nouni;repeated bugfruit 2, badgood 2;run;
proc glm;
  model Dbgbd666 Dbggd666 Dftbd666 Dftgd666 = /nouni;repeated bugfruit 2, badgood 2;run;
proc glm;
  model Dbgbd500 Dbggd500 Dftbd500 Dftgd500 = /nouni;repeated bugfruit 2, badgood 2;run;

proc glm; model Dbgbd999 Dbggd999 = /nouni;repeated badgood 2;title 'bugs only';run;
proc glm; model Dbgbd833 Dbggd833 = /nouni;repeated badgood 2;title 'bugs only';run;
proc glm; model Dbgbd666 Dbggd666 = /nouni;repeated badgood 2;title 'bugs only';run;
proc glm; model Dbgbd500 Dbggd500 = /nouni;repeated badgood 2;title 'bugs only';run;

proc glm; model Dftbd999 Dftgd999 = /nouni;repeated badgood 2;title 'fruit only';run;
proc glm; model Dftbd833 Dftgd833 = /nouni;repeated badgood 2;title 'fruit only';run;
proc glm; model Dftbd666 Dftgd666 = /nouni;repeated badgood 2;title 'fruit only';run;
proc glm; model Dftbd500 Dftgd500 = /nouni;repeated badgood 2;title 'fruit only';run;

/*bias analyses*/
proc means; var Bbgbdall Bbggdall Bftbdall Bftgdall;run;
proc glm; model Bbgbdall Bbggdall Bftbdall Bftgdall = /nouni;repeated bugfruit 2, badgood 2;run;
proc glm; model Bbgbdall Bbggdall = /nouni;repeated badgood 2;title 'bugs only';run;
proc glm; model Bftbdall Bftgdall = /nouni;repeated badgood 2;title 'fruit only';run;

proc glm; model  bbgbd999 bbggd999 bftbd999 bftgd999
                 bbgbd833 bbggd833 bftbd833 bftgd833
                 bbgbd666 bbggd666 bftbd666 bftgd666
      bbgbd500 bbggd500 bftbd500 bftgd500 = /nouni;repeated window 4, bugfruit 2, badgood 2;run;

proc means;
  var bbgbd999 bbggd999 bftbd999 bftgd999 bbgbd833 bbggd833 bftbd833 bftgd833
      bbgbd666 bbggd666 bftbd666 bftgd666 bbgbd500 bbggd500 bftbd500 bftgd500;run;
proc glm; model bbgbd999 bbggd999 = /nouni;repeated badgood 2;title 'bugs only';run;
proc glm; model bbgbd833 bbggd833 = /nouni;repeated badgood 2;title 'bugs only';run;
proc glm; model bbgbd666 bbggd666 = /nouni;repeated badgood 2;title 'bugs only';run;
proc glm; model bbgbd500 bbggd500 = /nouni;repeated badgood 2;title 'bugs only';run;

proc glm; model bftbd999 bftgd999 = /nouni;repeated badgood 2;title 'fruit only';run;
proc glm; model bftbd833 bftgd833 = /nouni;repeated badgood 2;title 'fruit only';run;
proc glm; model bftbd666 bftgd666 = /nouni;repeated badgood 2;title 'fruit only';run;
proc glm; model bftbd500 bftgd500 = /nouni;repeated badgood 2;title 'fruit only';run;

/*
proc corr;
    var Abugs Afruit Afrtbug;
    with Dbgbd999 Dbggd999 Dftbd999 Dftgd999 Dbgbd833 Dbggd833 Dftbd833 Dftgd833
     Dbgbd666 Dbggd666 Dftbd666 Dftgd666 Dbgbd500 Dbggd500 Dftbd500 Dftgd500;run;
proc corr;
    var Dbgbd999 Dbggd999 Dftbd999 Dftgd999 Dbgbd833 Dbggd833 Dftbd833 Dftgd833
     Dbgbd666 Dbggd666 Dftbd666 Dftgd666 Dbgbd500 Dbggd500 Dftbd500 Dftgd500;run;
proc corr;
    var Abugs Afruit Afrtbug;
    with Fruit999 Fruit833 Fruit666 Fruit500 Bugs999 Bugs833 Bugs666 Bugs500;run;
proc corr;
    var Fruit999 Fruit833 Fruit666 Fruit500 Bugs999 Bugs833 Bugs666 Bugs500;
    with fruitbug mathread fruitgd fruitbd;run;
proc corr;
   var fruitbug mathread fruitgd fruitbd FrtBg999 FrtBg833 FrtBg666 FrtBg500 FrtBug;run;
proc corr;
   var   Fruit999 Bugs999 Fruit833 Bugs833 Fruit666 Bugs666 Fruit500 Bugs500 Fruit Bugs;
   with fruitbug mathread fruitgd fruitbd;run;


proc sort; by sub;
proc print;
  var sub FrtBg999 FrtBg833 FrtBg666 FrtBg500 FrtBug;
proc print;
  var Fruit999 Bugs999 Fruit833 Bugs833 Fruit666 Bugs666 Fruit500 Bugs500 Fruit Bugs;run;
proc print;
  var sub Dbgbd999 Dbggd999 Dftbd999 Dftgd999 Dbgbd833 Dbggd833 Dftbd833 Dftgd833;
proc print;
  var sub Dbgbd666 Dbggd666 Dftbd666 Dftgd666 Dbgbd500 Dbggd500 Dftbd500 Dftgd500;run;

 */
